package com.lzh.shijicloudstack.controller;

import com.lzh.shijicloudstack.common.R;
import com.lzh.shijicloudstack.common.ResultUtil;
import com.lzh.shijicloudstack.model.dto.unit.AddUnitDto;
import com.lzh.shijicloudstack.model.dto.unit.EditUnitDto;
import com.lzh.shijicloudstack.model.entity.Unit;
import com.lzh.shijicloudstack.service.UnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 食材模块
 *
 * @author luzhiheng
 * @date 2025-01-25
 */
@Api(tags = "单位模块")
@RestController
@RequestMapping("/unit")
public class UnitController {

    @Resource
    private UnitService unitService;

    @ApiOperation(value = "查询单位列表")
    @PostMapping("/findList")
    public R<List<Unit>> findList() {
        return ResultUtil.success(unitService.list());
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return ResultUtil.success(unitService.removeById(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody @Valid AddUnitDto dto) {
        return ResultUtil.success(unitService.add(dto));
    }

    @ApiOperation(value = "修改")
    @PostMapping("/edit")
    public R<Boolean> edit(@RequestBody @Valid EditUnitDto dto) {
        return ResultUtil.success(unitService.edit(dto));
    }

}
